package Year22_Month07.day02;

import java.util.LinkedList;
import java.util.List;

public class 全排列 {
    List<List<Integer>> resList = new LinkedList<>();//结果集
    LinkedList<Integer> list = new LinkedList<>();
    //回溯
    public List<List<Integer>> permute(int[] nums) {
        backstacking(nums);
        return resList;
    }

    public void backstacking(int[] nums){
        if(list.size() == nums.length){
            resList.add(new LinkedList<>(list));
        }

        for (int i = 0; i < nums.length; i++) {
            if(list.contains(nums[i])) continue;
            list.add(nums[i]);
            backstacking(nums);
            list.removeLast();
        }
    }
}
